package com.example.demo.controller;

import com.example.demo.pojo.Category;
import com.example.demo.pojo.Product;
import com.example.demo.service.ICategoryService;
import com.example.demo.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ICategoryService ICategoryService;

    @Autowired
    private IProductService IProductService;


    @RequestMapping("/")
    public String showIndex(HttpServletRequest request) {
        HttpSession session = request.getSession();
//        TODO list 实际是热门商品的一个集合
        List<Product> search = IProductService.search();
        session.setAttribute("hotProducts",search);


//        TODO list 实际是最新商品的一个集合 s
        List<Integer> freshsList = Arrays.asList(1, 2, 1, 1, 1, 1, 1, 1, 1, 1);
        session.setAttribute("freshs",freshsList);

        List<Category> categoryList = ICategoryService.findAll();
        session.setAttribute("hotCategorys",categoryList);



        return "index";
    }
}
